package com.zrentech.order.data.dbhelper.builder;

import android.content.ContentValues;
import android.database.Cursor;

import com.zrentech.order.data.busibean.FoodBean;
import com.zrentech.order.data.dbhelper.DatabaseBuilder;

/**
 * 
 * 提供关于菜谱的创建和解析方面的功能
 * 
 * @author Leon
 */

public class FoodDBuilder extends DatabaseBuilder<FoodBean> {

	public static final String TRACK_ID = "id";
	public static final String TRACK_TYPEID = "typeID";
	public static final String TRACK_NAME = "name";
	public static final String TRACK_PRICE = "price";
	public static final String TRACK_DISCOUNT = "discount";
	public static final String TRACK_REMARK = "remark";
	private static final String TRACK_RATING = "rating";

	@Override
	public FoodBean build(Cursor query) {
		int columnId = query.getColumnIndex(TRACK_ID);
		int columnTypeID = query.getColumnIndex(TRACK_TYPEID);
		int columnName = query.getColumnIndex(TRACK_NAME);
		int columnPrice = query.getColumnIndex(TRACK_PRICE);
		int columnDiscount = query.getColumnIndex(TRACK_DISCOUNT);
		int columnRemark = query.getColumnIndex(TRACK_REMARK);
		int columnRating = query.getColumnIndex(TRACK_RATING);

		FoodBean menu = new FoodBean();
		menu.setId(query.getInt(columnId));
		menu.setTypeID(query.getInt(columnTypeID));
		menu.setName(query.getString(columnName));
		menu.setPrice(query.getDouble(columnPrice));
		menu.setDiscount(query.getDouble(columnDiscount));
		menu.setRemark(query.getString(columnRemark));
		menu.setRating(query.getDouble(columnRating));
		return menu;
	}

	@Override
	public ContentValues deconstruct(FoodBean track) {
		ContentValues values = new ContentValues();
		values.put(TRACK_ID, track.getId());
		values.put(TRACK_TYPEID, track.getTypeID());
		values.put(TRACK_NAME, track.getName());
		values.put(TRACK_PRICE, track.getPrice());
		values.put(TRACK_DISCOUNT, track.getDiscount());
		values.put(TRACK_REMARK, track.getRemark());
		values.put(TRACK_RATING, track.getRating());
		return values;
	}

}
